<template>
	<view class="content">
			<view class="cu-form-group">
				<view class="title">员工</view>
				<picker @change="pickerUser"  :value="receiveUserSelect"  range-key="nickName"  :range="users">
					<view class="picker">
						{{receiveUserSelect>-1?users[receiveUserSelect].nickName:'请选择要分配的员工'}}
					</view>
				</picker>
			</view>
			<view class="btn-box">
				<view class="submit-btn" @click="submit">提交</view>
			</view>
		 
	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		data() {
			return {
				users:[],
				receiveUserSelect:-1,
				form:{
					customerId:undefined,
					receiveUserId:undefined,
				}
			}
		},
		onLoad(options) {
			this.form.customerId=options.customerId;
			// 修改顶部导航背景色
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: '#39b54a',
				animation: {
					duration: 400,
					timingFunc: 'easeIn'
				}
			})
			var data={}
			var that=this;
			api.getSelectUserList(data).then(
				res => {
					if(res.code==200){
						that.users=res.data;
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						 
					}
				},
				rej => {}
			);
		},
		methods: {
			pickerUser(e){
				console.log(e.detail.value)
				this.receiveUserSelect=e.detail.value;
			},
			submit(){
				if (this.form.receiveUserId==-1) {
					uni.showToast({
						title: "请输入员工",
						icon: 'none',
					});
					return
				}
				this.form.receiveUserId=this.users[this.receiveUserSelect].userId;
				api.assign(this.form).then(
					res => {
						if(res.code==200){
							uni.showToast({
								title: '操作成功',
								duration: 2000
							});
							setTimeout(function() {
								uni.navigateBack({
								  success: () => {
								  }
								})
							}, 500);
						}
						else{
							uni.showToast({
								title: res.msg,
								icon: 'none',
							});
						}
						
					},
					rej => {}
				);
				
			}
			// 客户来源
			// sourcePicker(e) {
			// 	this.index = e.detail.value
			// },
		}
	}
</script>

<style scoped lang="scss">
	.content{
		margin-top: 20upx;
		.floow-cont{
			flex-direction: column;
			background-color: #ffffff;
			padding: 1rpx 30rpx;
			margin-top: 20upx;
			.title{
				text-align: justify;
				padding-right: 30upx;
				font-size: 30upx;
				position: relative;
				height: 60upx;
				line-height: 60upx;
			}
			 
		}
	}
	.btn-box{
		padding: 20upx 24upx;
		.submit-btn{
			height: 80upx;
			line-height: 80upx;
			text-align: center;
			font-size: 28upx;
			color: #fff;
			border-radius: 8upx;
			background: #39b54a;
		}
	}
</style>
